﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace FFmpegVideoClip.Lib.UtilityControlsTools
{
    [ValueConversion(typeof(double), typeof(string))]
    internal class DoubleToStringConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is double Result)
                return Math.Round(Result, 2, MidpointRounding.AwayFromZero).ToString();
            return "N/A";
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (double.TryParse(value.ToString(), out double Result))
                return Result;
            return 0d;
        }
    }
}
